<template>
	<div class="vue_app">
		<my-header :title="'确认订单'" :hasTitle="true" :hasBack="true" :goBack="goBack"></my-header>
		<div class="content" id="scanNodeBug">
			<div class="aui-content aui-margin-b-15">
				<ul class="aui-list aui-list-in">
					<li class="aui-list-item">
						<div class="aui-list-item-inner">
							<div class="aui-list-item-title">宁家鲜生<span v-if="storeName">- </span>{{storeName}}</div>
						</div>
					</li>
				</ul>
			</div>
			<!--商品列表-->
			<div class="aui-content choose_list">
				<ul class="aui-list aui-media-list">
					<li class="aui-list-item iscroll_list">
						<div id="co_orderGoods" class="aui-media-list-item-inner scroller_list" v-if="goodsList">
							<div class="aui-list-item-media" v-for="(item,index) in goodsList" :key="index">
								<div class="goodsTopShow" v-if="item.buyType == 2 || item.buyType == 3" :class="{goodsTopShowBackY:item.buyType == 2,goodsTopShowBackR:item.buyType == 3}">
									{{item.buyType == 2?'加价购':'赠品'}}
								</div>
								<img v-lazy="goodsImg(item)" style="height: 100%;width: 100%;"/>
								<em style="background:#EF5423;opacity: 0.6;">x{{item.goodsType == 7?'1':item.goodsNum}}</em>
							</div>
							<!--为了让用户能看到最后一个盒子-->
							<div class="aui-list-item-media" >
								
							</div>
						</div>
					</li>
				</ul>
				<div class="aui-list-item-arrow statistics">
					<!-- num-->
					<p>共<span id="co_totalPiece" style="padding-top: 0.5rem;">{{num}}</span>件</p>
				</div>
			</div>
			<div style="margin-bottom: 0.75rem;margin-top: -0.75rem;" v-if="false">
				<!--v-if="sendNameArr && sendNameArr.length != 0" -->
				<div class="aui-list-item-arrow01 server_show" v-if="sendNameArr && sendNameArr.length != 0" style="background-color: #fff2f2;padding: 0.2rem 0.5rem;">
					<div style="margin-left: 15;text-align: left;" class="aui-list-item-arrow_2">
						<h4>[赠品]</h4>
						<dl>
							<dd v-for="(item,index) in sendNameArr" :key="index">
								<!--v-for="(item,index) in sendNameArr" -->
								<font>{{item}}</font>
								<!--赠品名称  -->
								<!--<span>¥9.8×1</span>-->
							</dd>
						</dl>
					</div>
				</div>
			</div>
			<!--商品列表 end-->
			<!--信息列表-->
			<div class="aui-content aui-margin-b-15">
				<ul class="aui-list aui-list-in">
					<li class="aui-list-item">
						<div class="aui-list-item-inner">
							<div class="aui-list-item-title">商品金额</div>
							<div id="co_totalMoney" class="aui-list-item-right" v-if="goodsTotalMoney">¥{{goodsTotalMoney?Number(goodsTotalMoney).toFixed(2):'0.00'}} <span v-if="addMoney">(含加工费：¥{{''}})</span></div>
						</div>
					</li>
                    <!-- 活动优惠 -->
                    <li class="aui-list-item">
						<div class="aui-list-item-inner">
							<div class="aui-list-item-title">活动优惠</div> 
							<div id="co_totalMinis" class="aui-list-item-right">{{afterPromTotalMoney?'-':''}}¥{{afterPromTotalMoney?Number(afterPromTotalMoney).toFixed(2):'0.00'}}</div>
						</div>
					</li>
					<li class="aui-list-item aui-list-item-arrow">
						<div class="aui-list-item-inner" @click="showCoupon">
							<div class="aui-list-item-title">优惠券</div>																													<!--ticketList-->
							<!-- <div class="aui-list-item-right"><span style="color: #EF5423;padding-right: 0.1rem;" v-if="getTicketList.length === 0 && couponCount">{{couponCount}}</span>{{couponFlag}}</div> -->
                            <div class="aui-list-item-right"><span>{{discountMoneyByCoupon?'-':''}}¥{{discountMoneyByCoupon?Number(discountMoneyByCoupon).toFixed(2):'0.00'}}</span></div>
						</div>
					</li>
                    <!-- 总优惠 -->
					<!-- <li class="aui-list-item">
						<div class="aui-list-item-inner">
							<div class="aui-list-item-title">优惠金额</div>
							<div id="co_totalMinis" class="aui-list-item-right">¥{{discountMoney}}</div>
						</div>
					</li> -->
					<!--<li class="aui-list-item">
						<div class="aui-list-item-inner">
							<div class="aui-list-item-title">赠品加价</div>
							<div id="co_totalMinis" class="aui-list-item-right">￥{{discountMoney}}</div>
						</div>
					</li>-->
				</ul>
			</div>
			<!--信息列表 end-->
			<div class="aui-content aui-margin-b-15" v-if="false">
				<ul class="aui-list aui-form-list liuyan">
					<li class="aui-list-item">
						<div class="aui-list-item-inner" style="align-items:flex-start;">
							<div class="aui-list-item-label" style="line-height:2rem;">买家留言：</div>
							<div class="aui-list-item-input">
								<textarea placeholder="选填：输入留言信息" v-model="mynode" ref="note" maxlength="100"></textarea>
							</div>
						</div>
					</li>
				</ul>
			</div>
			<div class="total_sf">
				<h2><span id="co_realpay" >实付金额：¥ {{totalMoney?Number(totalMoney).toFixed(2):'0.00'}}</span> <p style="display: inline;" v-if="false">(省：¥ 1.00)</p> </h2>
				<p>如需发票，请到门店索取</p>
			</div>
			<!--立即下单-->
			<div style="height:4rem;" id="scrollTopBox"></div>
			<!--去结算 end-->
		</div>
		<confirm-gift-card ref="giftCard"></confirm-gift-card>
		<confirm-coupon ref="coupon" v-if="couponArr && couponArr.length" :couponArr="couponArr" :couponArrHtm="couponArrHtm" :couponMoney="couponM" :money="Number(totalMoney)" :getCouponMoney="changeCoupon"></confirm-coupon>
		<div class="zxSettle_acount aui-btn aui-btn-danger aui-btn-block aui-btn-sm" style="height: 2.5rem;line-height: 2.5rem;border-radius: 0px;font-size: 1rem;padding: 0px;">
			<div @click.stop="toPay">提交订单</div>
		</div>	
		<!--<confirm-order-pursekey ref="pursekey" :sendOrder="toPay"></confirm-order-pursekey>-->

	</div>
</template>

<script>
	import axios from 'axios';
	import { MessageBox } from '../../ui-components'
	import { Toast } from '../../utils/toast';
	import { mapGetters, mapActions, mapMutations } from "vuex";
	import MyHeader from "../header";
	import ConfirmCoupon from "../../real-components/ConfirmOrderNew/ConfirmOrderCoupon";
	import ConfirmOrderPursekey from "../../real-components/ConfirmOrder/ConfirmOrderPursekey";
	import ConfirmGiftCard from "../../real-components/ConfirmOrder/ConfirmGiftCard";
	import {saomagou} from "../../config/orderTypeCode";
	import {showLoading, hideLoading} from "../../utils/loading";
	export default {
		props: {},
		components: {
			"my-header": MyHeader,
			"ConfirmCoupon": ConfirmCoupon,
			"confirm-order-pursekey": ConfirmOrderPursekey,
			"ConfirmGiftCard": ConfirmGiftCard
		},
		computed: {
			...mapGetters('wxh', [
				'sessionId',
				'userInfo'
			]),
			...mapGetters('zx', [
				"getTicketList", "getAvailAmount", "getUseGiftCard","getOrderFlag"
			]),
			...mapGetters('cjy', [
				"selectGiftList", "selectLadderList", "buyMoreData"
			]),
			...mapGetters('qxz', [
				"getStoreList"
			]),
			ticketList() {
//				if(this.getTicketList.length === 0) {
//					if(this.couponCount){
//						this.couponFlag = "组可用";
//					}else{
//						this.couponFlag = '';
//					}
//				} else {
//					this.couponFlag = "已选择";
//				}
//				return this.couponFlag;
			},
			couponM() {

			},
			totalMoney() {
				return this.goodsPromTotalMoney;
			},
		},
		watch: {
			totalMoney(newVal,oldVal){
				// console.log(newVal,oldVal,this.getTicketList.length,'应付金额*--**--*-*-*-*-*-*-*-*-*-应付金额')
//				为确保数据同时渲染在请求完获取金额的接口后再显示优惠券信息
				// if(this.getTicketList.length === 0) {
				// 	if(this.couponCount){
				// 		this.couponFlag = "组可用";
				// 	}else{
				// 		this.couponFlag = '';
				// 	}
				// } else {
				// 	this.couponFlag = "已选择";
				// }
				// console.log(this.couponFlag,'应付金额*--**--*-*-*-*-*-*-*-*-*-应付金额2')
//				return this.couponFlag;
				
			}
		},
		data() {
			return {
				mynode: '',
				addMoney: '',
				goodsList: [],
				num: 0,
				orderData: null,
				goodsTotalMoney: 0, // 商品金额
                discountMoney: 0, // 总优惠的金额
                discountMoneyByCoupon:0, //优惠券优惠
                afterPromTotalMoney:0, //其他优惠
				goodsPromTotalMoney: 0, //实付金额
				couponArr: null, // 优惠券数组
				couponArrHtm: null, // 用于展示的优惠券数组
				couponFlag: '', //是否选择优惠券
				couponMoney: 0, // 优惠券优惠金额
				money: 0, //总金额
				storeOrderNo: null, // 线下订单号
				shopId: 0, // 线下门店
				moneyWithoutC: 0, //钱包免密金额
				keyall: null, // 钱包密码
				showMask: false, //是否需要用戶輸入密碼
				walletStatus: null, // 是否已经设置钱包密码
				sendNameArr: [], // 赠品名称数组  赠优惠券 赠商品
				shopCartIds:[],      //用于下单的参数  商品的rid
				couponCount:0, //可用优惠券
				clickFlag:true,  // 防止两次快速点击 调用两次下单接口
				storeName:null, // 扫码购门店名称
				ladderList:[],
				giftList:[],
				marks:false,//请求金额信息接口是否返回
			}
		},
		methods: {
			...mapMutations('zx', [
				"setUseGiftCard","setOrderFlag","setTicketList"
			]),
			...mapMutations('cjy', [
				'SET_OFF_LINE_SELECT_DATA'
			]),
			...mapActions('cjy',[
				"clearOffLineDetail"
			]),
			//获取门店
			getStoreName(){
				var code = localStorage.getItem('storeCode');
				var arr = this.getStoreList;
				for(let i = 0; i < arr.length; i++){
					if(arr[i].storeCode == code){
						this.storeName = arr[i].storeName;
					}
				}
//				console.log(code,'门店',this.getStoreList);
			},
			//获取商品信息
			getGoodsList() {
                // this.goodsList = this.$store.state.cjy.offLineSelectData;
				// console.log(JSON.stringify(this.goodsList),'购物车数据')
				// console.log(this.goodsList,'购物车数据')
				// this.getGoodsNum();
			},
			initData() {
				//				this.goodsList = this.$store.state.cjy.checkedCartList;
				//				var res = this.$route.query.res;
				//				var obj = res.data.data[0];
				//				console.log(res, '路由参数');
				//				if(res != null) {
				//					console.log(res.data.data[0].couponsInfo, '优惠券数组');
				//				}
				//				if(res != null) {
				//					this.goodsList = obj.goodsList;
				//					this.storeOrderNo = obj.storeOrderNo;
				//					this.shopId = obj.shopId;
				//					this.getGoodsNum();
				//					this.goodsTotalMoney = obj.goodsTotalMoney; // 优惠活动后的金额
				//					//this.goodsMoney = obj.goodsTotalMoney; // 用于计算优惠券金额
				//					this.goodsPromTotalMoney = obj.goodsPromTotalMoney; // 实付金额
				//					this.discountMoney = obj.discountMoney;
				//					this.couponArr = this.newCouponArr(obj.couponsInfo, 1);
				//					this.couponArrHtm = this.newCouponArr(obj.couponsInfo, 2);
				//
				//					var giftArr = res.data.data[0].giftVOPresentList.concat(res.data.data[0].couponCodePresentList);
				//					this.getSendNameArr(giftArr);
				//					console.log(giftArr,'赠品信息')
				//					console.log('首次渲染路由 实付金额', obj.goodsPromTotalMoney);
				//					console.log('首次渲染页面展示 实付金额', this.goodsPromTotalMoney);
				//					console.log(obj.goodsTotalMoney, 'res.data goodsTotalMoney获取路由参数2');
				//					console.log(this.couponArr, 'res.data.data couponsInfo获取路由参数3');
				//					console.log(obj.discountMoney, 'res.data.data couponsInfo 获取路由参数4');
				//				}
			},
			goodsImg(goodsItemData) {
				console.log("goodsItemData",goodsItemData)
	            // if (goodsItemData && goodsItemData.urllist) {
	            //     if(goodsItemData.urllist.length) {
	            //     	for(let i = 0 ; i < goodsItemData.urllist.length; i++){
				// 			console.log('goodsItemData',goodsItemData.urllist)
	            //     		if(goodsItemData.urllist[i].imgurltype == 1){
	            //     			return goodsItemData.urllist[i].imgurl
	            //     		} else if(goodsItemData.urllist[i].imgurltype == 0 && goodsItemData.urllist[i].imgurltype != 1 ) {
				// 				return goodsItemData.urllist[i].imgurl
				// 			} 
	            //     	}
	            //     } else {
	            //         return "static/image/demo2.png";
	            //     }
	            if (goodsItemData && goodsItemData.goodsImg) {
	                // if(goodsItemData.urllist.length) {
	                // 	for(let i = 0 ; i < goodsItemData.urllist.length; i++){
					// 		console.log('goodsItemData',goodsItemData.urllist)
	                // 		if(goodsItemData.urllist[i].imgurltype == 1){
	                // 			return goodsItemData.urllist[i].imgurl
	                // 		} else if(goodsItemData.urllist[i].imgurltype == 0 && goodsItemData.urllist[i].imgurltype != 1 ) {
					// 			return goodsItemData.urllist[i].imgurl
					// 		} 
	                // 	}
	                // } else {
	                //     return "static/image/demo2.png";
					// }
					return goodsItemData.goodsImg;
	            } else {
	                return "static/image/demo2.png";
	            }
	        },
			getSendNameArr(giftArr) {
				console.log(giftArr,'赠品包1');
				this.sendNameArr = [];
				var arr = giftArr;
				if(arr && arr.length) {
					for(let i = 0; i < arr.length; i++) {
						//				 		console.log(arr[i],'礼包');
						if(arr[i] != null && arr[i].giftName) {
							this.sendNameArr.push(arr[i].giftName);
						}
						if(arr[i] != null && arr[i].couponName) {
							this.sendNameArr.push(arr[i].couponName);
						}
					}
				}
				console.log('赠品包',this.sendNameArr)
			},
			//过滤优惠券数组增加同组标志
			newCouponArr(arr, num) {
				var newArr = [];
				for(let i = 0; i < arr.length; i++) {
					for(let j = 0; j < arr[i].couponCodeList.length; j++) {
						arr[i].couponCodeList[j].relIndex = i;
						newArr.push(arr[i].couponCodeList[j]);
					}
				}
				if(num === 1) {
					return newArr;
				} else if(num === 2) {
					return arr;
				}

			},
			//获取优惠券信息
			// getCoupon() {
			// 	let url = window.api.trade_host + "/marketCenter/getCalScanCodeCart/" + window.localStorage.getItem('storeCode') + "/false"
			// 	let config = {
			// 		url: url,
			// 		method: "GET",
			// 		headers: {
			// 			'sessionId': window.localStorage.getItem("sessionId")
			// 		}
			// 	};
			// 	axios(config).then((res) => {
			// 		if(res.data.data[0] && res.data.returnCode == 1) {
			// 			if(res.data.data[0].couponListCanBeUsed){
			// 				var arr = res.data.data[0].couponListCanBeUsed;
			// 				this.couponCount = res.data.data[0].couponListCanBeUsed.length;
			// 				console.log(res.data.data[0].couponListCanBeUsed.length);
			// 				console.log(arr, '线下扫码原生数组')
			// 				this.couponArr = this.newCouponArr(arr, 1);
			// 				this.couponArrHtm = this.newCouponArr(arr, 2);
			// 			}
			// 		}
			// 		//如果没有可使用的优惠券 或者 没有获取到优惠券信息 则直接调用获取金额信息接口    如果有可使用的优惠券 则在优惠券组件中获取最优优惠券再请求获取金额信息接口
			// 		if(!res.data.data[0] || !res.data.data[0].couponListCanBeUsed || res.data.data[0].couponListCanBeUsed.length == 0){
			// 			this.changeCoupon();
			// 		}
			// 	})
			// },
			changeCoupon(flag) {
				let url = window.api.trade_host + "/marketCenter/calScanCodeOrder";
				let params = {
					storeCode: window.api.storeCode //门店编码
				};
				console.log(this.couponFlag,'this.couponFlag获取优惠券')
				this.marks = false;//请求金额之前的标志 禁止下单
				let arr = this.getCouponParams();
				params.qrCodeList = arr;
				// console.log("缴费哦夹生饭111",this.giftList)
				if(this.giftList ) {
					// console.log("缴费哦夹生饭222",typeof(this.giftList))
					// console.log("缴费哦夹生饭333",this.giftList)
					params.giftVOList = this.giftList; // 赠品id 商品id 活动id  赠品次数 以逗号分隔
				}
				console.log(this.ladderList,'this.ladderList3')
				if(this.ladderList && this.ladderList.length != 0) {
					//					console.log(123458888)
					params.ladderIdList = this.ladderList; //商品id 阶梯满id 活动id  以逗号分隔
				}
				// 是否是第一次调用该接口 true代表第一次调用  false代表第二次开始调用
				params.callFirstTime = flag;
				let config = {
					url: url,
					method: 'POST',
					data: params,
					headers: {
						'sessionId': this.sessionId,
					},
				};

				try{
					axios(config).then((res) => {
						console.log(res.data.data[0], '初始化数据');
//						console.log(res.data.data[0].goodsPromTotalMoney, '优惠后总金额');
//						console.log(res.data.data[0].discountMoney, '优惠金额');
						this.sendNameArr = []; // 清空礼品包
						if(res.data && res.data.data && res.data.data.length){
							this.goodsList = res.data.data[0].scanGoodsList; //商品信息
							console.log("商品数据------------------------------",this.goodsList)
							this.goodsTotalMoney = Number(res.data.data[0].promTotalMoney); //商品金额
                            this.discountMoney = Number(res.data.data[0].orderDiscountMoney); // 总优惠金额
                            this.discountMoneyByCoupon = Number(res.data.data[0].discountMoneyByCoupon); //优惠券优惠
                            this.afterPromTotalMoney = Number(res.data.data[0].afterPromTotalMoney); //活动优惠
                            // this.addMoney = Number(res.data.data[0].totalWorkingFee); // 加工费用  暂时没有加工
							this.goodsPromTotalMoney = Number(res.data.data[0].resultOrderTotalMoney); //总金额  包含加工费 加价购等 实付金额
							// var giftArr = res.data.data[0].giftVOPresentList.concat(res.data.data[0].couponCodePresentList);
							var giftArr = []
							this.getSendNameArr(giftArr);
							//获取优惠券
							this.coupounsList =  res.data.data[0].coupounsList || [];
							this.couponArr = this.newCouponArr(this.coupounsList, 1);
							this.couponArrHtm = this.newCouponArr(this.coupounsList, 2);

							console.log(this.couponArr,this.couponArrHtm,'this.couponArrHtm')
							this.getGoodsNum();
							// this.getGoodsList(this.goodsList);
							this.marks = true;//请求成功后的标志
						}
						this.setOrderFlag(true); // 获取到金额信息  允许用户点击提交订单按钮
						hideLoading();  //隐藏loading
					})
				}catch(err){
					hideLoading();
				}
			},
			goInfomation() {
				this.$router.push({
					path: 'orderInformation',
					query: {
						arr: this.goodsList
					}
				});
			},
			//	       	 展示优惠券
			showCoupon() {
				console.log(this.$refs.coupon,"sss")
				if(this.$refs.coupon){
					this.$refs.coupon.showCover()
				}
			},
			//获取总个数
			getGoodsNum() {
				this.num = 0;
				console.log(this.num,'this.num')
				if(this.goodsList.length != 0) {
					for(let i = 0; i < this.goodsList.length; i++) {
						if(this.goodsList[i].goodsType == 7) {
							this.num += 1
						} else {
							this.num += this.goodsList[i].goodsNum;
							
						}
					}
				}
			},
			goBack() {
				window.history.back();
			},
			checkeParams() {

			},
			getCouponParams() {
				let arr = this.getTicketList;
				let newArr = [];
				for(let i = 0; i < arr.length; i++) {
					newArr.push(arr[i].qrCode);
				}
				return newArr;
			},
			//获取购物车商品活动信息
			getSelectGiftList() {

				var arr = this.selectGiftList; // 满增阶梯
				
				if(arr && arr.length != 0) {
					for(var i = 0; i < arr.length; i++) {
						
						//如果存在goodsCode就传goodsCode 如果不存在goodsCode但是存在goodsCodeList就便利之后传过去
						if(arr[i].goodsCode){
							var newArr = [];
							newArr.push(arr[i].goodsCode);   //商品code
							newArr.push(arr[i].promLadderId);    // 阶梯满id
							newArr.push(arr[i].promCode);  //活动code
							this.ladderList.push(JSON.stringify(newArr));
							
						}else if(arr[i].goodsCodeList && arr[i].goodsCodeList.length){
							
							for(let j = 0; j < arr[i].goodsCodeList.length; j++) {
								var newArr = [];
								newArr.push(arr[i].goodsCodeList[j]);  //商品列表
								newArr.push(arr[i].promLadderId);  // 订单返利 阶梯满id 
								newArr.push(arr[i].promCode);      // 活动code
								this.ladderList.push(JSON.stringify(newArr));
							}
							
						}
					}
					console.log(this.ladderList,'this.ladderList1')
					
				}
			},
			getSelectLadderList() {
				var arr = this.selectLadderList; // 返利阶梯   只有订单返利阶梯才有可能送单张优惠券

				if(arr && arr.length != 0) {
					for(var i = 0; i < arr.length; i++) {
						
						//newArr.push(arr[i].goodsList);
						for(let j = 0; j < arr[i].goodsList.length; j++) {
							var newArr = [];
							newArr.push(arr[i].goodsList[j]);  //商品列表
							newArr.push(arr[i].promLadderId);  // 订单返利 阶梯满id 
							newArr.push(arr[i].promCode);      // 活动code
							this.ladderList.push(JSON.stringify(newArr));
						}
					}

				}
				console.log(this.ladderList,'this.ladderList2')
			},
			getBuyMoreData() {
				var arr = this.buyMoreData;
				var giftVoList = arr.filter ( (item) => {
					return item.giftVO && item.giftVO.giftGoodsList && item.giftVO.giftGoodsList.length > 0
				})
				console.log(giftVoList,'giftVoList5555555555')
				if(giftVoList.length != 0) {
					for(var i = 0; i < giftVoList.length; i++) {
						for(let j = 0; j < giftVoList[i].goodsList.length; j++) {
							var newArr = [];
							newArr.push(giftVoList[i].goodsList[j]);
							newArr.push(giftVoList[i].promCode);
							newArr.push(giftVoList[i].selectNum);
							if(giftVoList[i].selectNum != 0) {
								this.giftList.push(JSON.stringify(newArr));
							}

						}
					}
				}
			},
			//获取购物车商品活动信息结束
			getLadderParams(){
				return this.ladderList || [];
			},
			getGiftParams(){
				return this.giftList || [];
			},
			// 获取商品rid
			getShopCartIds(){
				//区分大件商品和常规商品  0 常规   1 大件
				for(var i = 0; i < this.goodsList.length; i++){
					var obj = {}
					obj['rid'] = this.goodsList[i].rid;
					this.shopCartIds.push(obj);
				}
				return this.shopCartIds;
			},
			  //如果是安卓机,调整页面margin-bottom供用户看到input框
	        initInputStyle() {
	            let isAndroid = navigator.userAgent.indexOf("Android") > -1;
	            if (isAndroid) {
	            	console.log("/-*****-/---1---");
					let box = document.getElementById('scanNodeBug');
					let box2 = document.getElementById('scrollTopBox');
					box2.style.height = '18rem';
	                let scrollTopContainer = document.body;
//	                console.log(box.scrollTop,'11111111111')
					box.scrollTop = 450;
//					console.log(box.scrollTop,'11111111111')
	                //给一个scrollTop值的变化，自动滑上去
	                let distance = parseInt(getComputedStyle(box, null).marginBottom.slice(0, -2));
	                let duration = 200 / 16.7;
	                let speed = distance / duration;
	                this.scrollAnim = setInterval(() => {
	                    scrollTopContainer.scrollTop += speed;
	                    if (scrollTopContainer.scrollTop >= distance) {
	                    	console.log("/-*****-/---3---");
	                        scrollTopContainer.scrollTop = distance;
	                        clearInterval(this.scrollAnim);
	                    }
	                }, 16.7);
	            }
	        },
	        unsetStyle() {
//	        	console.log(999)
	            //清除计时器
	            clearInterval(this.scrollAnim);
	            this.scrollAnim = null;
	            let box = document.getElementById('scanNodeBug');
				let box2 = document.getElementById('scrollTopBox');
				box2.style.height = '4rem';
				box.scrollTop = 220;
				 console.log(box.scrollTop,'22222222222')
	        },
	        //监听买家留言框的focus事件 开始
	        initTextareaFocusEvent() {
	        	console.log(this.$refs.note)
	            this.$refs.note.onfocus = () => {
	                console.log("input框框获取到了焦点");
	                this.initInputStyle();
	            }
	            this.$refs.note.onblur = () => {
	                console.log("失去焦点");
	                //重置样式
	                this.unsetStyle();
	                
	            }
	        },
	       //从支付页点返回处理
			checkPayBack(){
				let flag = this.$store.getters.getNativeBackFlagForPay;
				let flag2 = !this.$store.state.cjy.offLineSelectData || this.$store.state.cjy.offLineSelectData == 0;
				if(flag && flag2){
					this.$store.commit("setNativeBackFlagForPay", false);
					this.$router.push({path:'order',query:{orderStatus:1}});
					return true;
				}else if(!flag && flag2){
					this.$router.push({path:'home'});
					return true;
				}
				return false;
			},
			async toPay() {
				
				// 判断获取金额信息接口是否已返回数据  没返回就禁止下单
        		// if(!this.getOrderFlag){
        		// 	return;
        		// }
				
				//防止多次点击下单
        		if(!this.clickFlag){
        			return ;
        		}
				
				this.clickFlag = false;  // 点击后置为禁用状态
				var that = this;
				var myTimer = setTimeout(function(){
        			that.clickFlag = true;
        		},5000)
				
				let params = {
					cartId: this.goodsList[0].cartId,
					note: this.mynode,
					storeCode: window.api.storeCode,
					// shopCartIds: this.getShopCartIds()
				};
				// console.log(this.couponFlag,'this.couponFlag')
				// if(this.couponFlag != '') {
					let couponParams = this.getCouponParams();
					params.qrCodeList = couponParams;
				// }
				
				var ladderIdList = this.getLadderParams(); // 获取阶梯返利满赠参数
        		if(ladderIdList && ladderIdList.length != 0){
        			params.ladderIdList = ladderIdList;
        		}
        		
                var giftVOList = this.getGiftParams();
                console.log(giftVOList,'giftVOList000000000')
        		if(giftVOList && giftVOList.length != 0){
        			params.giftVOList = giftVOList;
        		}
				params.walletPayed = 0;
				console.log(params, '请求参数');
                
				let config = {
	            	url: window.api.trade_host+'/order/insertScanOrderDto',
	            	method: 'POST',
	            	data: params,
	            	headers: {'sessionId': this.sessionId, 'Content-Type':'application/json', 'Accept' : 'application/json'},
	            }
				try {
                    var res =  await axios(config);
                    console.log(res);
                    console.log(res.readyState, res.status);
                    console.log(res);
                    console.log(res.data);
                    
                    this.clickFlag = true;  //接口返回  解除点击禁用
                    
                    if(res.status == 200) {
                        console.log(res);
                        if(res.data.returnCode === 1) {
                            console.log('订单生成');
                            
                            var arr = [];
                            this.SET_OFF_LINE_SELECT_DATA(arr);  //清除购物车数据
                            
                            var orderNo = res.data.data[0];
                            
                            if(this.totalMoney !== 0){
                                this.$router.push({name: "pay", params: {orderNo:orderNo,orderType:saomagou}});
                            }else{
                                this.$router.push({path: "scanOrder", query: {scanOrder:orderNo,orderType:saomagou}});
                            }

                        } else {
                            console.log('下单失败')
                            Toast({
                                message: res.data.msg,
                                duration: 1000,
                                type: 'fail'
                            });
                        }
                    } else {
                        Toast({
                            message: '生成订单失败',
                            duration: 1000,
                            type: 'fail'
                        });
                    }
				} catch(err) {
					this.clickFlag = true;  //接口返回  解除点击禁用
					Toast({
						message: '生成订单失败',
						duration: 1000,
						type: 'fail'
					});
				}
			}
		},
		beforeDestroy() {
			let arr = [];
			hideLoading();
			this.setTicketList(arr);  //清空优惠券
			this.setUseGiftCard(false);
			this.setOrderFlag(false); // 将提交按钮设置为禁用状态
			//清楚购物车数据
			this.clearOffLineDetail();
			//	    	this.setFpObj({});   // 重置发票对象的在indexvue中实现
		},
		created() {
			
			console.log(12345678999996666999999999999999)
			if (this.checkPayBack()) return;  //判断从支付页点原生返回 处理
			
			
			this.initData();
			// this.getGoodsList();
			// this.getCoupon();
			this.getSelectGiftList(); //获取满增阶梯信息 ladderList
			this.getSelectLadderList(); // 获取返利阶梯信息  ladderList
			this.getBuyMoreData(); // 获取 买增 信息  giftList
			this.changeCoupon(true);  //初始化金额信息
			this.getStoreName();  // 获取扫码购门店名称
			
			
			
		},
		mounted() {
				//展示loading
			showLoading();
			setTimeout(() => {
				hideLoading();
			},3000)
//	        this.initTextareaFocusEvent();
	    },
	}
</script>

<style scoped="scoped">
	.settle_accounts {
		height: 3rem;
		background: rgba(255, 255, 255, 0.9);
		overflow: hidden;
		position: fixed;
		width: 100%;
		left: 0;
		bottom: -1px;
		display: table;
		border-top: 1px solid #eaeaea;
		z-index: 1;
	}
	
	.scroller_list {
		overflow-y: auto;
	}
	
	.iscroll_list {
		height: 5.5rem !important;
	}
	
	.scroller_list {
		position: relative;
	}
	
	.vue_app {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: space-between;
	}
	
	.content {
		flex: 1;
		overflow-y: auto;
		width: 100%;
	}
	.zxSettle_acount {
		height: 3rem;
		background: rgba(255, 255, 255, 0.9);
		width: 100%;
		border-top: 1px solid #eaeaea;
		padding: 0.5rem 0.75rem 0;
	}
	.choose_list .statistics {
		padding-top: 1.9rem;
	}
	.goodsTopShow{
        opacity: 0.6;
        position: absolute;
        left: 0;top: 0;
        color: #ffffff;
        padding: 0 0.1rem;
        font-size:12px;
    }
    .goodsTopShowBackY{
        background:#faa73c;
    }
    .goodsTopShowBackR{
        background: #EF5423;
    }
</style>